計算程式執行時間

#C#

Posted by Phyxsius on 2023-09-28

internal class Program
{
    private static void Main(string[] args)
    {
        System.Diagnostics.Stopwatch stopWatch = new System.Diagnostics.Stopwatch();
        stopWatch.Start();  //計算程式時間開始

        /* 程式執行開始 */
        for(int i=1; i<=1000; i++)
        {
            Console.Write(i + ",");
        }
        Console.WriteLine();
        /* 程式執行結束 */

        stopWatch.Stop();   //計算程式時間結束

        //程式執行時間以毫秒計算,若要改成秒需除以1000
        Console.WriteLine("程式執行時間(秒):" + (stopWatch.Elapsed.TotalMilliseconds / 1000));
    }
}

#C#







Related Posts

android error 有關舊程式碼改成mvvm架構

android error 有關舊程式碼改成mvvm架構

[學學ReactNative] DAY1 - 前言與動機:為何選擇 React Native?

[學學ReactNative] DAY1 - 前言與動機:為何選擇 React Native?

焦糖幫你記ChatBot || Line Bot 實作

焦糖幫你記ChatBot || Line Bot 實作


Comments